package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.retrofitModule.response.GetCashLogResponse;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/11/14.
 */

public class AccountDetailAdapter extends BaseAdapter {
    private GetCashLogResponse getCashLogResponses;
    private Context mContext;

    public AccountDetailAdapter(GetCashLogResponse getCashLogResponses, Context mContext) {
        this.getCashLogResponses = getCashLogResponses;
        this.mContext = mContext;
    }

    public void setDatas(GetCashLogResponse getCashLogResponses){
        this.getCashLogResponses = getCashLogResponses;
    }

    public GetCashLogResponse getDatas(){
        return getCashLogResponses;
    }

    @Override
    public int getCount() {
        return getCashLogResponses.getList().size();
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public GetCashLogResponse.ListBean getItem(int i) {
        return getCashLogResponses.getList().get(i);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(mContext).inflate(R.layout.account_child_item, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }

        holder.money.setText((Float.parseFloat(getItem(i).getAmount()) + Float.parseFloat(getItem(i).getOffer1()) + Float.parseFloat(getItem(i).getOffer2())) + getItem(i).getUnit());
        holder.time.setText(getItem(i).getSubmit_time());
        holder.type.setText(getItem(i).getType3());

        return view;
    }


    static class ViewHolder {
        @BindView(R.id.type)
        TextView type;
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.money)
        TextView money;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
